const sysAppService = require('../../service/dao/sys/sys_app');

// 读取白名单
const blacklist = configure.get('blacklist')

// 全局中间件 - jwt 验证
module.exports = function (req, res, next) {
    if (blacklist.freedom.includes(req.route.path)) {
        next();
    } else {
        let token = req.headers['authorization'] || req.headers['Authorization'] || req.query.jwt || req.body.jwt || '';
        token = token.replace(/Bearer /i, '')

        sysAppService.check(token).then(payload => {
            req.jwt = payload;
            next();
        }).catch(e=>{
            res.jsonWrap(null,-9999,e.message);
        })
    }
};


